package com.lujieni.idempotent.controller;

import com.lujieni.idempotent.core.annotation.Idempotent;
import com.lujieni.idempotent.core.keyresolver.impl.ExpressionIdempotentKeyResolver;
import com.lujieni.idempotent.dto.PersonDTO;
import lombok.Data;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {

    @PostMapping("/hello")
    @Idempotent(timeout = 60)
    public void hello(@RequestBody PersonDTO personDTO123321) throws InterruptedException {
        System.out.println(personDTO123321);
        Thread.sleep(10 * 1000);
    }

    @PostMapping("/bye")
    @Idempotent(timeout = 60, keyResolver = ExpressionIdempotentKeyResolver.class, keyArg = "{#dto.name, #dto.age}")
    public void bye(@RequestBody PersonDTO dto) throws InterruptedException {
        System.out.println(dto);
        Thread.sleep(10 * 1000);
    }




}
